﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Anuntiomatic
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool ownsmutex = false;
            using (Mutex mutex = new Mutex(true, "AE64783F-C09C-42D3-B7D8-CD0EE5D5C0EF", out ownsmutex))
            {
                if (ownsmutex)
                {
                    // Add the event handler for handling UI thread exceptions to the event.
                    Application.ThreadException += new ThreadExceptionEventHandler(Form1_UIThreadException);

                    // Set the unhandled exception mode to force all Windows Forms errors to go through 
                    // our handler.
                    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

                    // Add the event handler for handling non-UI thread exceptions to the event. 
                    AppDomain.CurrentDomain.UnhandledException +=
                        new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new FrmMain());
                }
            }
        }
        private static void Form1_UIThreadException(object sender, ThreadExceptionEventArgs t)
        {
            MessageBox.Show(t.Exception.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        // Handle the UI exceptions by showing a dialog box, and asking the user whether 
        // or not they wish to abort execution. 
        // NOTE: This exception cannot be kept from terminating the application - it can only  
        // log the event, and inform the user about it.  
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.ExceptionObject.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}
